<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 600px;
            margin: 0 auto;
            border: 1px solid rebeccapurple;
            /* height: 500px; */
        }
        .box .title{
            display: flex;
            flex-wrap: wrap;
            border-bottom: 1px solid #000;
        }
        .box .title a{
            width: 50px;
            display: block;
            /* background-color: aqua; */
            height: 50px;
            line-height: 50px;
            text-align: center;
            text-decoration: none;
            padding: 0 20px;
            color: #333;
        }
        .main .item{
            border-bottom: 3px solid red;
            padding: 10px 10px ;
        }
        .main img{
            width: 100%;
        }
        .page{
            display: flex;
            justify-content: space-between;
            
        }
        .page button{
            height: 50px;
            font-size: 40px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="title">
            <a data-tpye="All" href="javascript:;">最新</a>
        </div>
        <div class="main">
            
        </div>
        <div class="page">
            <button class="s">上一页</button>
            <button class="x">下一页</button>
        </div>
    </div>
</body>
<!-- <script src="../../../jQuery/jquery.js"></script> -->
<script src="../../../zepto.js"></script>
<script>
$(function(){
    let types = []
   $.ajax({
    //    async:true,
       url:'https://gank.io/api/v2/categories/Article',
       success:function(res){
        types = types.concat(res.data)

        $.ajax({
       url:'https://gank.io/api/v2/categories/Girl',
       success:function(res){
        types = types.concat(res.data)
        
        types.forEach(function(item){
            $('.box .title').append(`<a data-type=${item.type} href="javascript:;">${item.title}</a>`)
        })
       }
   })
       }
   })

   let page = 1
   let count = 10
   let getlist = function(type ='All'){
    //    console.log(`https://gank.io/api/v2/data/category/${type}/type/All/page/${page}/count/${count}`)
    // console.log(type)
    $.get(`https://gank.io/api/v2/data/category/All/type/${type}/page/${page}/count/${count}`,function(res){
        $('.main').empty()
       res.data.forEach(function(item){
        $('.box .main').append(`<div class="item">
                <h3>${item.title}</h3>
                <img src="${item.images[0].startsWith('http') ?item.images:'../image/111.webp' }" >
                </div>`)
       })
   })
   }
   getlist()

  
   let type = 'all'
   $('.box .title').on('click','a',function(){
       page = 1
        type = $(this).data('type')
   getlist(type)
   })


   $('.page .x').on('click',function(){
       page+=1
       getlist(type)
   })

   









})











</script>
</html>